<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .yellow {
      width: 200px;
      height: 10px;
      background-color: yellow;
      border-radius: 5px;
    }
    .red {
      width: 140px;
      height: 100%;
      margin: 0 auto;
      background-color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <p>todo list</p>
    <input type="text" v-model="thing">
    <button @click="add">添加</button>
    <p>待办事项</p>
    <ul>
      <li v-for="(item, index) in todoList" :key="index">
        <span>{{item}}</span>
        <button @click="del(index)">del</button>
      </li>
    </ul>
    <p>完成事项</p>
    <ul>
      <li v-for="(item, index) in doneList" :key="index">
        <span>{{item}}</span>
      </li>
    </ul>
    <hr>
    <div class="yellow" :style="{transform: 'scale(' + x + ')'}">
      <div class="red" @click="big"></div>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        thing: '',
        todoList: JSON.parse(localStorage.getItem('todoList')) || [],
        doneList: JSON.parse(localStorage.getItem('doneList')) || [],
        x: 1
      },
      methods: {
        del(index) {
          // 添加到已完成
          this.doneList.push(this.todoList[index]);
          localStorage.setItem('doneList', JSON.stringify(this.doneList));
          // 删除代办事项
          this.todoList.splice(index, 1);
          localStorage.setItem('todoList', JSON.stringify(this.todoList));
        },
        add() {
          // 不能为空
          if(this.thing) {
            this.todoList.push(this.thing);
            localStorage.setItem('todoList', JSON.stringify(this.todoList));
            this.thing = '';
          }
        },
        big() {
          this.x += 0.1
        }
      },
    }) 
  </script>
</body>
</html>